﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication01
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //登陆
        protected void logins_Click(object sender, EventArgs e)
        {
            var uid = txtUsername.Text.Trim();
            var pwd = txtPassword.Text.Trim();

            var sql = string.Format("select * from users where username='{0}'and password='{1}'",uid,pwd);
            var dt = DbHelper.GetDataTable(sql);

            if(dt.Rows.Count == 1)
            {
                var IsActived = (bool)dt.Rows[0].ItemArray[3];

                var IsDeleted = (bool)dt.Rows[0].ItemArray[4];

                if (IsDeleted)
                {
                    lbcomments.Text = "当前用户过期或被删除，无法登陆";
                }
                else
                {
                    if (IsActived)
                    {
                        Response.Redirect("Default.aspx");
                    }
                }
            }
            else
            {
                lbcomments.Text = "用户名或密码输入错误，或账号、密码错误等等。";
            }

        }
        //取消
        protected void cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
    }
}